import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    children: [{
      path: '/users',
      name: 'users',
      component: () => import('../components/users/users.vue'),
      meta:{list:[{title:"用户管理"},{title:"用户列表"}]}
    },{
      path: '/categories',
      name: 'categories',
      component: () => import('../components/goods/categories.vue'),
      meta:{list:[{title:"商品管理"},{title:"商品分类"}]}
    },{
      path: '/goods',
      name: 'goods',
      component: () => import('../components/goods/goods.vue'),
      meta:{list:[{title:"商品管理"},{title:"商品列表"}]}
    },
    {
      path: '/addgoods',
      name: 'addgoods',
      component: () => import('../components/goods/addgoods.vue'),
      meta:{list:[{title:"商品管理"},{title:"添加商品"}]}
    },{
      path: '/params',
      name: 'params',
      component: () => import('../components/goods/params.vue'),
      meta:{list:[{title:"商品管理"},{title:"分类参数"}]}
    },{
      path: '/orders',
      name: 'orders',
      component: () => import('../components/orders/orders.vue'),
      meta:{list:[{title:"订单管理"},{title:"订单列表"}]}
    },{
      path: '/reports',
      name: 'reports',
      component: () => import('../components/reports/reports.vue'),
      meta:{list:[{title:"数据统计"},{title:"数据报表"}]}
    },{
      path: '/rights',
      name: 'rights',
      component: () => import('../components/rights/rights.vue'),
      meta:{list:[{title:"权限管理"},{title:"权限列表"}]}
    },{
      path: '/roles',
      name: 'roles',
      component: () => import('../components/rights/roles.vue'),
      meta:{list:[{title:"权限管理"},{title:"角色列表"}]}
    },]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    next()
  } else {
    if (localStorage.getItem("houtaitoken")) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
